#include "StdAfx.h"
#include "ImageBlob.h"

namespace dotfont{

int ImageBlob::getEncoderClsid( Type T, CLSID* pClsid )
{
	wstring format = getFormatString(T);

	UINT  num = 0;          // number of image encoders
	UINT  size = 0;         // size of the image encoder array in bytes

	ImageCodecInfo* pImageCodecInfo = NULL;

	GetImageEncodersSize(&num, &size);
	if(size == 0)
		return -1;  // Failure

	pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
	if(pImageCodecInfo == NULL)
		return -1;  // Failure

	GetImageEncoders(num, size, pImageCodecInfo);

	for(UINT j = 0; j < num; ++j)
	{
		if( format == pImageCodecInfo[j].MimeType)
		{
			*pClsid = pImageCodecInfo[j].Clsid;
			free(pImageCodecInfo);
			return j;  // Success
		}    
	}

	free(pImageCodecInfo);
	return -1;  // Failure
}

wstring ImageBlob::getFormatString( Type T )
{
	switch (T)
	{
	case tPNG:
		return L"image/png";
		break;
	}

	assert(!"Unsupported image format.");
	return L"";
}

} // namespace dotfont
